<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>vmap</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="vlowres.html" title="vlowres" />
    <link rel="next" href="vmirror.html" title="vmirror" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">vmap</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="vlowres.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="vmirror.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="vmap"></a>
      <div class="titlepage"></div>
      <a id="IndexVmap" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">vmap</span>
        </h2>
        <p>vmap — 
      Maps elements from a vector according to indexes contained in another vector.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp164651728"></a>
        <h2>Description</h2>
        <p>
      Maps elements from a vector onto another according to the indexes of a this vector.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp164717536"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>vmap</strong></span>  ifn1, ifn2, ielements [,idstoffset, isrcoffset]</pre>
      </div>
      <div class="refsect1">
        <a id="idp164719424"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>ifn1</em></span> - number of the table where the vectorial signal will be copied, and which contains the mapping vector
    </p>
        <p>
      <span class="emphasis"><em>ifn2</em></span> - number of the table hosting the vectorial signal to be copied
    </p>
        <p>
      <span class="emphasis"><em>ielements</em></span> - number of elements to process
    </p>
        <p>
      <span class="emphasis"><em>idstoffset</em></span> - index offset for destination table (<span class="emphasis"><em>ifn1</em></span>)
    </p>
        <p>
      <span class="emphasis"><em>isrcoffset</em></span> - index offset for source table (<span class="emphasis"><em>ifn2</em></span>)
    </p>
      </div>
      <div class="refsect1">
        <a id="idp164725392"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>vmap</em></span> maps elements of <span class="emphasis"><em>ifn2</em></span> according to the values of table <span class="emphasis"><em>ifn1</em></span>. Elements of <span class="emphasis"><em>ifn1</em></span> are treated as indexes of table <span class="emphasis"><em>ifn2</em></span>, so element values of <span class="emphasis"><em>ifn1</em></span> must not exceed the length of <span class="emphasis"><em>ifn2</em></span> table otherwise a Csound will report an error. Elements of <span class="emphasis"><em>ifn1</em></span> are treated as integers, so any fractional part will be truncated. There is no interpolation performed on this operation.
    </p>
        <p>In practice, what happens is that the elements of <span class="emphasis"><em>ifn1</em></span> are used as indexes to <span class="emphasis"><em>ifn2</em></span>, and then are replaced by the corresponding elements from <span class="emphasis"><em>ifn2</em></span>. <span class="emphasis"><em>ifn1</em></span> must be different from <span class="emphasis"><em>ifn2</em></span>, otherwise the results are unpredictable. Csound will produce an init error if they are not.
    </p>
        <p>
      All these operators (<a class="link" href="vaddv.html" title="vaddv"><em class="citetitle">vaddv</em></a>, <a class="link" href="vsubv.html" title="vsubv"><em class="citetitle">vsubv</em></a>, <a class="link" href="vmultv.html" title="vmultv"><em class="citetitle">vmultv</em></a>, <a class="link" href="vdivv.html" title="vdivv"><em class="citetitle">vdivv</em></a>, <a class="link" href="vpowv.html" title="vpowv"><em class="citetitle">vpowv</em></a>, <a class="link" href="vexpv.html" title="vexpv"><em class="citetitle">vexpv</em></a>, <a class="link" href="vcopy.html" title="vcopy"><em class="citetitle">vcopy</em></a> and <a class="link" href="vmap.html" title="vmap"><em class="citetitle">vmap</em></a>) are designed to be used together with other opcodes that operate with vectorial signals such as, <a class="link" href="vcella.html" title="vcella"><em class="citetitle">vcella</em></a>, <a class="link" href="adsynt.html" title="adsynt"><em class="citetitle">adsynt</em></a>, <a class="link" href="adsynt2.html" title="adsynt2"><em class="citetitle">adsynt2</em></a>, etc. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp164744480"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the vmap opcode. It uses the file <a class="ulink" href="examples/vmap.csd" target="_top"><em class="citetitle">vmap.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp164746336"></a>
          <p class="title">
            <strong>Example 1006. Example of the vmap opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in</span>
-odac           -iadc     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o vmap.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="ohdr">ksmps</span> <span class="op">=</span> 256
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
gisize <span class="op">=</span> 64

gitable <span class="ohdr">ftgen</span> 0, 0, gisize, 10, 1  <span class="comment">;Table to be processed</span>
gimap1 <span class="ohdr">ftgen</span>  0, 0, gisize, <span class="op">-</span>7, gisize<span class="op">-</span>1, gisize<span class="op">-</span>1, 0 <span class="comment">; Mapping function to reverse table</span>
gimap2 <span class="ohdr">ftgen</span> 0, 0, gisize, <span class="op">-</span>5, 1, gisize<span class="op">-</span>1, gisize<span class="op">-</span>1  <span class="comment">; Mapping function for PWM</span>
gimap3 <span class="ohdr">ftgen</span> 0, 0, gisize, <span class="op">-</span>7, 1, (gisize<span class="op">/</span>2)<span class="op">-</span>1, gisize<span class="op">-</span>1, 1, 1, (gisize<span class="op">/</span>2)<span class="op">-</span>1, gisize<span class="op">-</span>1  <span class="comment">; Double frequency</span>

<span class="oblock">instr</span> 1  <span class="comment">;Hear an oscillator using gitable</span>
asig <span class="opc">oscil</span> 10000, 440, gitable
<span class="opc">outs</span> asig,asig
<span class="oblock">endin</span>

<span class="oblock">instr</span> 2  <span class="comment">;Reverse the table (no sound change, except for a single click</span>
<span class="opc">vmap</span> gimap1, gitable, gisize
<span class="opc">vcopy_i</span> gitable, gimap1, gisize
<span class="opc">turnoff</span>
<span class="oblock">endin</span>

<span class="oblock">instr</span> 3  <span class="comment">;Non-interpolated PWM (or phase waveshaping)</span>
<span class="opc">vmap</span> gimap2, gitable, gisize
<span class="opc">vcopy_i</span> gitable, gimap2, gisize
<span class="opc">turnoff</span>
<span class="oblock">endin</span>

<span class="oblock">instr</span> 4  <span class="comment">;Double frequency</span>
<span class="opc">vmap</span> gimap3, gitable, gisize
<span class="opc">vcopy_i</span> gitable, gimap3, gisize
<span class="opc">turnoff</span>
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 8

<span class="stamnt">i</span> 2 2 1
<span class="stamnt">i</span> 3 4 1
<span class="stamnt">i</span> 4 6 1

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp164750528"></a>
        <h2>Credits</h2>
        <p>Written by Gabriel Maldonado.</p>
        <p>New in Csound 5 (Previously available only on CsoundAV)</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="vlowres.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="vmirror.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">vlowres </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> vmirror</td>
        </tr>
      </table>
    </div>
  </body>
</html>
